package org.example.demo.raw;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.fisco.bcos.sdk.abi.FunctionReturnDecoder;
import org.fisco.bcos.sdk.abi.TypeReference;
import org.fisco.bcos.sdk.abi.datatypes.Address;
import org.fisco.bcos.sdk.abi.datatypes.Event;
import org.fisco.bcos.sdk.abi.datatypes.Function;
import org.fisco.bcos.sdk.abi.datatypes.Type;
import org.fisco.bcos.sdk.abi.datatypes.Utf8String;
import org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32;
import org.fisco.bcos.sdk.abi.datatypes.generated.Uint256;
import org.fisco.bcos.sdk.abi.datatypes.generated.Uint8;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple2;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple3;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple8;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.contract.Contract;
import org.fisco.bcos.sdk.crypto.CryptoSuite;
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.eventsub.EventCallback;
import org.fisco.bcos.sdk.model.CryptoType;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.fisco.bcos.sdk.model.callback.TransactionCallback;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;

@SuppressWarnings("unchecked")
public class TeaAssetManagement extends Contract {
    public static final String[] BINARY_ARRAY = {"608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550611f3e806100606000396000f3006080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630ac982ce146100a95780631abab434146102f557806328b9c3f5146105415780635eb38a6c146105b85780637e84eb4b1461062f578063995484cf14610680578063d5f39488146106d1578063d5f64d5614610728578063ddae86cb146107e5578063ef5d6bbb14610838575b600080fd5b3480156100b557600080fd5b506100d86004803603810190808035600019169060200190929190505050610889565b604051808960001916600019168152602001806020018060200188815260200180602001806020018773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200186600481111561013e57fe5b60ff16815260200185810385528c818151815260200191508051906020019080838360005b8381101561017e578082015181840152602081019050610163565b50505050905090810190601f1680156101ab5780820380516001836020036101000a031916815260200191505b5085810384528b818151815260200191508051906020019080838360005b838110156101e45780820151818401526020810190506101c9565b50505050905090810190601f1680156102115780820380516001836020036101000a031916815260200191505b50858103835289818151815260200191508051906020019080838360005b8381101561024a57808201518184015260208101905061022f565b50505050905090810190601f1680156102775780820380516001836020036101000a031916815260200191505b50858103825288818151815260200191508051906020019080838360005b838110156102b0578082015181840152602081019050610295565b50505050905090810190601f1680156102dd5780820380516001836020036101000a031916815260200191505b509c5050505050505050505050505060405180910390f35b34801561030157600080fd5b506103246004803603810190808035600019169060200190929190505050610b5e565b604051808960001916600019168152602001806020018060200188815260200180602001806020018773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200186600481111561038a57fe5b60ff16815260200185810385528c818151815260200191508051906020019080838360005b838110156103ca5780820151818401526020810190506103af565b50505050905090810190601f1680156103f75780820380516001836020036101000a031916815260200191505b5085810384528b818151815260200191508051906020019080838360005b83811015610430578082015181840152602081019050610415565b50505050905090810190601f16801561045d5780820380516001836020036101000a031916815260200191505b50858103835289818151815260200191508051906020019080838360005b8381101561049657808201518184015260208101905061047b565b50505050905090810190601f1680156104c35780820380516001836020036101000a031916815260200191505b50858103825288818151815260200191508051906020019080838360005b838110156104fc5780820151818401526020810190506104e1565b50505050905090810190601f1680156105295780820380516001836020036101000a031916815260200191505b509c5050505050505050505050505060405180910390f35b34801561054d57600080fd5b506105b66004803603810190808035600019169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610e67565b005b3480156105c457600080fd5b5061062d6004803603810190808035600019169060200190929190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506110e5565b005b34801561063b57600080fd5b5061067e6004803603810190808035600019169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611363565b005b34801561068c57600080fd5b506106cf6004803603810190808035600019169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115d7565b005b3480156106dd57600080fd5b506106e661184b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561073457600080fd5b506107e36004803603810190808035600019169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611870565b005b3480156107f157600080fd5b506108146004803603810190808035600019169060200190929190505050611bf9565b6040518082600481111561082457fe5b60ff16815260200191505060405180910390f35b34801561084457600080fd5b506108876004803603810190808035600019169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611c2e565b005b6001602052806000526040600020600091509050806000015490806001018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561093b5780601f106109105761010080835404028352916020019161093b565b820191906000526020600020905b81548152906001019060200180831161091e57829003601f168201915b505050505090806002018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109d95780601f106109ae576101008083540402835291602001916109d9565b820191906000526020600020905b8154815290600101906020018083116109bc57829003601f168201915b505050505090806003015490806004018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a7d5780601f10610a5257610100808354040283529160200191610a7d565b820191906000526020600020905b815481529060010190602001808311610a6057829003601f168201915b505050505090806005018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b1b5780601f10610af057610100808354040283529160200191610b1b565b820191906000526020600020905b815481529060010190602001808311610afe57829003601f168201915b5050505050908060060160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060060160149054906101000a900460ff16905088565b600060608060006060806000806000600160008b60001916600019168152602001908152602001600020905080600001548160010182600201836003015484600401856005018660060160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168760060160149054906101000a900460ff16868054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610c705780601f10610c4557610100808354040283529160200191610c70565b820191906000526020600020905b815481529060010190602001808311610c5357829003601f168201915b50505050509650858054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610d0c5780601f10610ce157610100808354040283529160200191610d0c565b820191906000526020600020905b815481529060010190602001808311610cef57829003601f168201915b50505050509550838054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610da85780601f10610d7d57610100808354040283529160200191610da8565b820191906000526020600020905b815481529060010190602001808311610d8b57829003601f168201915b50505050509350828054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610e445780601f10610e1957610100808354040283529160200191610e44565b820191906000526020600020905b815481529060010190602001808311610e2757829003601f168201915b505050505092509850985098509850985098509850985050919395975091939597565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610f2d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f4f6e6c79206465706c6f7965720000000000000000000000000000000000000081525060200191505060405180910390fd5b600160008460001916600019168152602001908152602001600020905060006004811115610f5757fe5b8160060160149054906101000a900460ff166004811115610f7457fe5b141515610fe9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f526571756972652070726f63657373696e6720636f6d706c657465640000000081525060200191505060405180910390fd5b81816005019080519060200190611001929190611ded565b5060028160060160146101000a81548160ff0219169083600481111561102357fe5b021790555082600019167f0471a275ee0872ffc4fca85ab175638c66be1d2c0f9f580a007db6514e0829ca6001846040518083600481111561106157fe5b60ff16815260200180602001828103825260158152602001807f4f776e657273686970207472616e7366657272656400000000000000000000008152506020019250505060405180910390a2505050565b600060016000836000191660001916815260200190815260200160002060060160149054906101000a900460ff169050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611cf4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f4f6e6c79206465706c6f7965720000000000000000000000000000000000000081525060200191505060405180910390fd5b6001600084600019166000191681526020019081526020016000209050818160060160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600019167f0471a275ee0872ffc4fca85ab175638c66be1d2c0f9f580a007db6514e0829ca8260060160149054906101000a900460ff1660405180826004811115611d9c57fe5b60ff16815260200180602001828103825260158152602001807f4f776e657273686970207472616e7366657272656400000000000000000000008152506020019250505060405180910390a2505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611e2e57805160ff1916838001178555611e5c565b82800160010185558215611e5c579182015b82811115611e5b578251825591602001919060010190611e40565b5b509050611e699190611eed565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611eae57805160ff1916838001178555611edc565b82800160010185558215611edc579182015b82811115611edb578251825591602001919060010190611ec0565b5b509050611ee99190611eed565b5090565b611f0f91905b80821115611f0b576000816000905550600101611ef3565b5090565b905600a165627a7a72305820ce293859a7bfcaaa8d159cb571292518fc1ffdb057ef92d80be8251189abb1680029"};

    public static final String BINARY = org.fisco.bcos.sdk.utils.StringUtils.joinAll("", BINARY_ARRAY);

    public static final String[] SM_BINARY_ARRAY = {};

    public static final String SM_BINARY = org.fisco.bcos.sdk.utils.StringUtils.joinAll("", SM_BINARY_ARRAY);

    public static final String[] ABI_ARRAY = {"[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"teaAssets\",\"outputs\":[{\"name\":\"batchId\",\"type\":\"bytes32\"},{\"name\":\"teaType\",\"type\":\"string\"},{\"name\":\"origin\",\"type\":\"string\"},{\"name\":\"harvestTime\",\"type\":\"uint256\"},{\"name\":\"processingInfo\",\"type\":\"string\"},{\"name\":\"qualityReport\",\"type\":\"string\"},{\"name\":\"currentOwner\",\"type\":\"address\"},{\"name\":\"stage\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"getTeaAssetDetails\",\"outputs\":[{\"name\":\"batchId\",\"type\":\"bytes32\"},{\"name\":\"teaType\",\"type\":\"string\"},{\"name\":\"origin\",\"type\":\"string\"},{\"name\":\"harvestTime\",\"type\":\"uint256\"},{\"name\":\"processingInfo\",\"type\":\"string\"},{\"name\":\"qualityReport\",\"type\":\"string\"},{\"name\":\"currentOwner\",\"type\":\"address\"},{\"name\":\"stage\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"name\":\"_processingData\",\"type\":\"string\"}],\"name\":\"updateProcessingInfo\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"name\":\"_reportHash\",\"type\":\"string\"}],\"name\":\"submitQualityReport\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"name\":\"_buyer\",\"type\":\"address\"}],\"name\":\"markAsSold\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"name\":\"_transporter\",\"type\":\"address\"}],\"name\":\"startTransporting\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"deployer\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"name\":\"_teaType\",\"type\":\"string\"},{\"name\":\"_origin\",\"type\":\"string\"}],\"name\":\"createTeaAsset\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"}],\"name\":\"getAssetStage\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_batchId\",\"type\":\"bytes32\"},{\"name\":\"_newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"batchId\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"timestamp\",\"type\":\"uint256\"}],\"name\":\"AssetCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"batchId\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"newStage\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"updateInfo\",\"type\":\"string\"}],\"name\":\"AssetUpdated\",\"type\":\"event\"}]"};

    public static final String ABI = org.fisco.bcos.sdk.utils.StringUtils.joinAll("", ABI_ARRAY);

    public static final String FUNC_TEAASSETS = "teaAssets";

    public static final String FUNC_GETTEAASSETDETAILS = "getTeaAssetDetails";

    public static final String FUNC_UPDATEPROCESSINGINFO = "updateProcessingInfo";

    public static final String FUNC_SUBMITQUALITYREPORT = "submitQualityReport";

    public static final String FUNC_MARKASSOLD = "markAsSold";

    public static final String FUNC_STARTTRANSPORTING = "startTransporting";

    public static final String FUNC_DEPLOYER = "deployer";

    public static final String FUNC_CREATETEAASSET = "createTeaAsset";

    public static final String FUNC_GETASSETSTAGE = "getAssetStage";

    public static final String FUNC_TRANSFEROWNERSHIP = "transferOwnership";

    public static final Event ASSETCREATED_EVENT = new Event("AssetCreated", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>(true) {}, new TypeReference<Uint256>() {}));
    ;

    public static final Event ASSETUPDATED_EVENT = new Event("AssetUpdated", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>(true) {}, new TypeReference<Uint8>() {}, new TypeReference<Utf8String>() {}));
    ;

    protected TeaAssetManagement(String contractAddress, Client client, CryptoKeyPair credential) {
        super(getBinary(client.getCryptoSuite()), contractAddress, client, credential);
    }

    public static String getBinary(CryptoSuite cryptoSuite) {
        return (cryptoSuite.getCryptoTypeConfig() == CryptoType.ECDSA_TYPE ? BINARY : SM_BINARY);
    }

    public Tuple8<byte[], String, String, BigInteger, String, String, String, BigInteger> teaAssets(byte[] param0) throws ContractException {
        final Function function = new Function(FUNC_TEAASSETS, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(param0)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Address>() {}, new TypeReference<Uint8>() {}));
        List<Type> results = executeCallWithMultipleValueReturn(function);
        return new Tuple8<byte[], String, String, BigInteger, String, String, String, BigInteger>(
                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue(), 
                (String) results.get(2).getValue(), 
                (BigInteger) results.get(3).getValue(), 
                (String) results.get(4).getValue(), 
                (String) results.get(5).getValue(), 
                (String) results.get(6).getValue(), 
                (BigInteger) results.get(7).getValue());
    }

    public Tuple8<byte[], String, String, BigInteger, String, String, String, BigInteger> getTeaAssetDetails(byte[] _batchId) throws ContractException {
        final Function function = new Function(FUNC_GETTEAASSETDETAILS, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Address>() {}, new TypeReference<Uint8>() {}));
        List<Type> results = executeCallWithMultipleValueReturn(function);
        return new Tuple8<byte[], String, String, BigInteger, String, String, String, BigInteger>(
                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue(), 
                (String) results.get(2).getValue(), 
                (BigInteger) results.get(3).getValue(), 
                (String) results.get(4).getValue(), 
                (String) results.get(5).getValue(), 
                (String) results.get(6).getValue(), 
                (BigInteger) results.get(7).getValue());
    }

    public TransactionReceipt updateProcessingInfo(byte[] _batchId, String _processingData) {
        final Function function = new Function(
                FUNC_UPDATEPROCESSINGINFO, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_processingData)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] updateProcessingInfo(byte[] _batchId, String _processingData, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_UPDATEPROCESSINGINFO, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_processingData)), 
                Collections.<TypeReference<?>>emptyList());
        asyncExecuteTransaction(function, callback);
        return null;
    }

    public String getSignedTransactionForUpdateProcessingInfo(byte[] _batchId, String _processingData) {
        final Function function = new Function(
                FUNC_UPDATEPROCESSINGINFO, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_processingData)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple2<byte[], String> getUpdateProcessingInfoInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_UPDATEPROCESSINGINFO, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple2<byte[], String>(

                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue()
                );
    }

    public TransactionReceipt submitQualityReport(byte[] _batchId, String _reportHash) {
        final Function function = new Function(
                FUNC_SUBMITQUALITYREPORT, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_reportHash)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] submitQualityReport(byte[] _batchId, String _reportHash, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_SUBMITQUALITYREPORT, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_reportHash)), 
                Collections.<TypeReference<?>>emptyList());
        asyncExecuteTransaction(function, callback);
        return null;
    }

    public String getSignedTransactionForSubmitQualityReport(byte[] _batchId, String _reportHash) {
        final Function function = new Function(
                FUNC_SUBMITQUALITYREPORT, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_reportHash)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple2<byte[], String> getSubmitQualityReportInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_SUBMITQUALITYREPORT, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple2<byte[], String>(

                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue()
                );
    }

    public TransactionReceipt markAsSold(byte[] _batchId, String _buyer) {
        final Function function = new Function(
                FUNC_MARKASSOLD, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_buyer)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] markAsSold(byte[] _batchId, String _buyer, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_MARKASSOLD, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_buyer)), 
                Collections.<TypeReference<?>>emptyList());
        asyncExecuteTransaction(function, callback);
        return null;
    }

    public String getSignedTransactionForMarkAsSold(byte[] _batchId, String _buyer) {
        final Function function = new Function(
                FUNC_MARKASSOLD, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_buyer)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple2<byte[], String> getMarkAsSoldInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_MARKASSOLD, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Address>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple2<byte[], String>(

                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue()
                );
    }

    public TransactionReceipt startTransporting(byte[] _batchId, String _transporter) {
        final Function function = new Function(
                FUNC_STARTTRANSPORTING, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_transporter)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] startTransporting(byte[] _batchId, String _transporter, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_STARTTRANSPORTING, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_transporter)), 
                Collections.<TypeReference<?>>emptyList());
        asyncExecuteTransaction(function, callback);
        return null;
    }

    public String getSignedTransactionForStartTransporting(byte[] _batchId, String _transporter) {
        final Function function = new Function(
                FUNC_STARTTRANSPORTING, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_transporter)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple2<byte[], String> getStartTransportingInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_STARTTRANSPORTING, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Address>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple2<byte[], String>(

                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue()
                );
    }

    public String deployer() throws ContractException {
        final Function function = new Function(FUNC_DEPLOYER, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
        return executeCallWithSingleValueReturn(function, String.class);
    }

    public TransactionReceipt createTeaAsset(byte[] _batchId, String _teaType, String _origin) {
        final Function function = new Function(
                FUNC_CREATETEAASSET, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_teaType), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_origin)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] createTeaAsset(byte[] _batchId, String _teaType, String _origin, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_CREATETEAASSET, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_teaType), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_origin)), 
                Collections.<TypeReference<?>>emptyList());
        asyncExecuteTransaction(function, callback);
        return null;
    }

    public String getSignedTransactionForCreateTeaAsset(byte[] _batchId, String _teaType, String _origin) {
        final Function function = new Function(
                FUNC_CREATETEAASSET, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_teaType), 
                new org.fisco.bcos.sdk.abi.datatypes.Utf8String(_origin)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple3<byte[], String, String> getCreateTeaAssetInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_CREATETEAASSET, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple3<byte[], String, String>(

                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue(), 
                (String) results.get(2).getValue()
                );
    }

    public BigInteger getAssetStage(byte[] _batchId) throws ContractException {
        final Function function = new Function(FUNC_GETASSETSTAGE, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint8>() {}));
        return executeCallWithSingleValueReturn(function, BigInteger.class);
    }

    public TransactionReceipt transferOwnership(byte[] _batchId, String _newOwner) {
        final Function function = new Function(
                FUNC_TRANSFEROWNERSHIP, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_newOwner)), 
                Collections.<TypeReference<?>>emptyList());
        return executeTransaction(function);
    }

    public byte[] transferOwnership(byte[] _batchId, String _newOwner, TransactionCallback callback) {
        final Function function = new Function(
                FUNC_TRANSFEROWNERSHIP, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_newOwner)), 
                Collections.<TypeReference<?>>emptyList());
        asyncExecuteTransaction(function, callback);
        return null;
    }

    public String getSignedTransactionForTransferOwnership(byte[] _batchId, String _newOwner) {
        final Function function = new Function(
                FUNC_TRANSFEROWNERSHIP, 
                Arrays.<Type>asList(new org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32(_batchId), 
                new org.fisco.bcos.sdk.abi.datatypes.Address(_newOwner)), 
                Collections.<TypeReference<?>>emptyList());
        return createSignedTransaction(function);
    }

    public Tuple2<byte[], String> getTransferOwnershipInput(TransactionReceipt transactionReceipt) {
        String data = transactionReceipt.getInput().substring(10);
        final Function function = new Function(FUNC_TRANSFEROWNERSHIP, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Address>() {}));
        List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
        return new Tuple2<byte[], String>(

                (byte[]) results.get(0).getValue(), 
                (String) results.get(1).getValue()
                );
    }

    public List<AssetCreatedEventResponse> getAssetCreatedEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(ASSETCREATED_EVENT, transactionReceipt);
        ArrayList<AssetCreatedEventResponse> responses = new ArrayList<AssetCreatedEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            AssetCreatedEventResponse typedResponse = new AssetCreatedEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.batchId = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.timestamp = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public void subscribeAssetCreatedEvent(String fromBlock, String toBlock, List<String> otherTopics, EventCallback callback) {
        String topic0 = eventEncoder.encode(ASSETCREATED_EVENT);
        subscribeEvent(ABI,BINARY,topic0,fromBlock,toBlock,otherTopics,callback);
    }

    public void subscribeAssetCreatedEvent(EventCallback callback) {
        String topic0 = eventEncoder.encode(ASSETCREATED_EVENT);
        subscribeEvent(ABI,BINARY,topic0,callback);
    }

    public List<AssetUpdatedEventResponse> getAssetUpdatedEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(ASSETUPDATED_EVENT, transactionReceipt);
        ArrayList<AssetUpdatedEventResponse> responses = new ArrayList<AssetUpdatedEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            AssetUpdatedEventResponse typedResponse = new AssetUpdatedEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.batchId = (byte[]) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.newStage = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.updateInfo = (String) eventValues.getNonIndexedValues().get(1).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public void subscribeAssetUpdatedEvent(String fromBlock, String toBlock, List<String> otherTopics, EventCallback callback) {
        String topic0 = eventEncoder.encode(ASSETUPDATED_EVENT);
        subscribeEvent(ABI,BINARY,topic0,fromBlock,toBlock,otherTopics,callback);
    }

    public void subscribeAssetUpdatedEvent(EventCallback callback) {
        String topic0 = eventEncoder.encode(ASSETUPDATED_EVENT);
        subscribeEvent(ABI,BINARY,topic0,callback);
    }

    public static TeaAssetManagement load(String contractAddress, Client client, CryptoKeyPair credential) {
        return new TeaAssetManagement(contractAddress, client, credential);
    }

    public static TeaAssetManagement deploy(Client client, CryptoKeyPair credential) throws ContractException {
        return deploy(TeaAssetManagement.class, client, credential, getBinary(client.getCryptoSuite()), "");
    }

    public static class AssetCreatedEventResponse {
        public TransactionReceipt.Logs log;

        public byte[] batchId;

        public BigInteger timestamp;
    }

    public static class AssetUpdatedEventResponse {
        public TransactionReceipt.Logs log;

        public byte[] batchId;

        public BigInteger newStage;

        public String updateInfo;
    }
    
    /**
     * 根据状态码获取中文状态描述
     * @param stage 状态码
     * @return 中文状态描述
     */
    public static String getAssetStageDesc(BigInteger stage) {
        if (stage == null) {
            return "未知";
        }
        int stageValue = stage.intValue();
        switch (stageValue) {
            case 0:
                return "已创建";
            case 1:
                return "运输中";
            case 2:
                return "质检完成";
            case 3:
                return "已售出";
            default:
                return "未知状态(" + stageValue + ")";
        }
    }
}
